/*
 * control_cmd.c
 *
 *  Created on: Jan 5, 2000
 *      Author: root
 */

#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <semaphore.h>
#include <error.h>
#include <malloc.h>
#include <sys/mman.h>
#include <sys/time.h>

#include <assert.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>

#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/select.h>

#include "control_cmd.h"
#include "reg_rw.h"


int asyn_reset_xdma()
{
	int bypass=open("/dev/xdma0_bypass", O_RDWR | O_SYNC);
	unsigned long long word=0x5a5a0000000000c0;
	reg_bypass_control(bypass,word);
	word=0x5a5a00000000000f;
	reg_bypass_control(bypass,word);
	close(bypass);
	return 1;
}


int asyn_start_xdma()
{
	int bypass=open("/dev/xdma0_bypass", O_RDWR | O_SYNC);
	unsigned long long word=0x5a5a000000000030;
	reg_bypass_control(bypass,word);
	close(bypass);
	return 1;
}


int asyn_stop_xdma()
{
	int bypass=open("/dev/xdma0_bypass", O_RDWR | O_SYNC);
	unsigned long long word=0x5a5a0000000000c0;
	reg_bypass_control(bypass,word);
	close(bypass);
	return 1;
}


int asyn_set_fiberNum(int num,int time)
{
	if(num<1||num>6)
	{
		num=4;
	}
	if(time<16||time>64)
	{
		time=32;
	}
	int bypass=open("/dev/xdma0_bypass", O_RDWR | O_SYNC);
	int temp=num<<24;
	int temp_time=time<<12;
	unsigned long long word=0x5a5a000000000100;
	word=word|temp;
	word=word|temp_time;
	reg_bypass_control(bypass,word);
	close(bypass);
	return 1;
}


int asyn_set_intSrc(int index)
{
	int bypass=open("/dev/xdma0_bypass", O_RDWR | O_SYNC);
	unsigned long long word=0;
	if(index==0)
	{
		word=0x5a5a0000f0000000;
		reg_bypass_control(bypass,word);
	}
	else if(index==1)
	{
		word=0x5a5a0000c0000000;
		reg_bypass_control(bypass,word);
	}
	else if(index==2)
	{
		word=0x5a5a000030000000;
		reg_bypass_control(bypass,word);
	}
	else
	{
		printf("not available index\n");
	}
	close(bypass);
	return 1;
}
